package com.example.hewei.smarttransport.Request;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by 何伟 on 2017/3/7.
 */

public class ForgetRequest extends TrafficRequest {
    // action name
    private static final String ACTION = "findPassword";

    private String userName;

    private String email;

    public ForgetRequest(String userName) {
        super(userName);
    }

    @Override
    protected String getActionName() {
        return ACTION;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEmail() {
        return email;
    }


    @Override
    protected String onGetJasonBody() {
        JSONObject jsonObj = new JSONObject();
        try {
            jsonObj.put("username", userName);// 用户名
            return jsonObj.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return super.onGetJasonBody();
    }

    //处理服务器回传的结果
    protected void onJasonParese(String responseStr) {
        try{
            JSONObject jsonRespObj = new JSONObject(responseStr);
            if (jsonRespObj != null) {
                if (jsonRespObj.has("result")) {
                    String result = jsonRespObj.getString("result");
                    // 判断请求是否成功
                    if (result.equalsIgnoreCase("ok")) {
                        isSuccess = true;
                    } else {
                        isSuccess = false;
                    }
                }
                if (jsonRespObj.has("email")) {
                    email = jsonRespObj.getString("email");
                }
            }
        }
        catch (JSONException e) {
            isSuccess = false;
            e.printStackTrace();
        }

    }

}

